package com.AAA.service.Impl.sas;

import com.AAA.entity.MyPage;
import com.AAA.entity.sas.TTestRecondSas;
import com.AAA.entity.User;
import com.AAA.entity.sas.TTestRecondSas1;
import com.AAA.service.sas.TTestRecondSasService;
import com.AAA.dao.sas.TTestRecondSasMapper;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.Date;
import java.util.List;

/**
 * (TTestRecondSas)表服务实现类
 *
 * @author 何泽明
 * @since 2022-11-05 08:58:21
 */
@Service
public class TTestRecondSasServiceImpl implements TTestRecondSasService {
   @Autowired
   private TTestRecondSasMapper mapper;

   @Override
   public boolean add(HttpServletRequest request, HttpSession session) {
      User user = (User) session.getAttribute("user");
      String createby= user.getUsername();
      String recond = request.getParameter("recond");
      String remark = request.getParameter("remark");
      String username = request.getParameter("username");
      Integer rid= mapper.selectridbyusername(username);
      Integer pid= mapper.selectpidbyrid(username);
      Date createtime= new Date();
      boolean all=mapper.insertall(createby,recond,remark,rid,pid,createtime);
      return all;
   }

   @Override
   public PageInfo selectall(MyPage myPage, TTestRecondSas1 tTestRecondSas) {
      PageHelper.startPage(myPage.getPage(), myPage.getLimit());
      List<TTestRecondSas1> select = mapper.selectmohu(tTestRecondSas);
      PageInfo pageInfo = new PageInfo<>(select);
      return pageInfo;
   }

   @Override
   public boolean update(TTestRecondSas tTestRecondSas) {
      tTestRecondSas.setUpdatetime(new Date());
      int all=mapper.updateByPrimaryKeySelective(tTestRecondSas);
      if (all>0){
         return true;
      }else {
         return false;
      }
   }

   @Override
   public Integer delete(Integer id) {
      //deleteByPrimaryKey 获取实体类定义的id值  进行删除
      return mapper.deleteByPrimaryKey(id);
   }

   @Override
   public Integer selectidbyusername(String username) {
      Integer id=mapper.selectidbyusername(username);
      return id;
   }

   @Override
   public Integer selectusernameidbyusername(Integer id) {
      Integer usernameid=mapper.selectusernameidbyusername(id);
      return usernameid;
   }
}

